<?php
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends BaseController {
	function _before_edit(){
		$classl=M('classl')
		       ->field(array('classl_id','classl_name'))
		       ->select();
		$this->assign('classl',$classl);
    $brand=M("Brand")
          ->field(array('brand_id as value','brand_name as name'))
          ->select();
    $this->assign('brand',$brand);
	}
	function _before_add(){
		$this->_before_edit();
	}
	//获取二级分类
	function getclassm(){
        $classl_id=I('id',0);
        $array=M('classm')
              ->where(array('classl_id'=>$classl_id))
              ->field(array('classm_id','classm_name'))
              ->select();
        if(count($array)){
        	suc($array);
        }else{
        	err('无相应分类');
        }
	}
	function getclasss(){
        $classm_id=I('id',0);
        $array=M('classs')
              ->where(array('classm_id'=>$classm_id))
              ->field(array('classs_id','classs_name'))
              ->select();
        if(count($array)){
        	suc($array);
        }else{
        	err('无相应分类');
        }
	}
  //相册删除
  function albumDel(){
      $path=I('path');
      $path=str_replace(__ROOT__, '', $path);

      $id=I('id');
      $fp=fopen($path,'r');
      if($fp){
           //if(!unlink($path)){
               unlink($path);
               //die($path);
           //}
          
       
               
      }
      $model=M('goods');
       $map=array('go_id'=>$id);
       $img=$model
           ->where($map)
           ->getField('go_pics');
       $array=explode(',',$img);
       //键值反转
       $array=array_flip($array);
       //删除键名为要删除图片路径
       unset($array[$path]);
       //再返回来
       $array=array_flip($array);
       $string=implode(',',$array);
       
      $model->where($map)
           ->save(array('go_pics'=>$string));

  }
}              